<?php
	class loginControl extends Control{
		function __auto(){
			if(isset($_SESSION['admin_id'])){
				go("index/index");
			}
		}
		function login(){
			$this->display();
		}
		//登录
		function check(){
			$db  = M("admin");
			$row = $db->find("username='{$_POST['username']}'");
			if(!$row){
				$this->error("用户不存在");
			}
			if($row['password'] !=md5($_POST['password'])){
				$this->error("密码错误");
			}
			$_SESSION['username']=$row['username'];
			$_SESSION['admin_id']=$row['admin_id'];
			go("index/index");

		}
		//显示验证码
		function code(){
			$code = new code();
			$code->show();
		}
		function check_username(){
			$db = M("admin");
			if($db->all("username='{$_POST['username']}'")){
				echo 1;
			}
		}
		//验证密码
		function check_password(){
			$db = M("admin");
			if($row= $db->find("username='{$_POST['username']}'")){
				if($row['password'] == md5($_POST['password'])){
					echo 1;
				}
			}
		}
		//验证码验证
		function check_code(){
			$db = M("admin");
			if(strtoupper($_POST['code'])==$_SESSION['code']){
				echo 1;
			}
		}











	}
?>